package com.gump.essay.leetcode;

/**
 * @auther zzc
 * @date 2021 03 21
 */
public class 最大子序和 {

    public static void main(String[] args) {

        int[] nums = new int[]{1, 2, -3, 6, 7, 5, 4};
        int result = getResult(nums);
        System.out.println(result);

    }

    private static int getResult(int[] nums) {

        //子数组和
        int tmpSum = 0;
        //最大值
        int res = nums[0];
        //遍历
        for (int num : nums) {
            tmpSum = Math.max(tmpSum + num, num);
            res = Math.max(tmpSum, res);
        }
        return res;
    }
}
